import $axios from '@/sever'

export const getData = async (
  url: string,
  pageNum: number,
  pageSize: number,
  searchParams?: Record<string, any>
) => {
  const searchQuery = new URLSearchParams(searchParams).toString()
  return await $axios.get(
    `${url}?pageNum=${pageNum}&pageSize=${pageSize}&${searchQuery}`
  )
}

export const createItem = async (url: string, data: any) => {
  return (await $axios.post(url, data)).data
}

export const deleteItem = async (url: string, id: string) => {
  return (await $axios.delete(`${url}/${id}`)).data
}

export const updateItem = async (url: string, id: string, data: any) => {
  return (await $axios.put(`${url}`, { id, data })).data
}
